/* -----------------------------------------------------------------------
 *   Copyright (C) 2008 by Denjs
 *   dplsoft@pisem.net
 *   http://qdroid.berlios.de
 * -----------------------------------------------------------------------
 *   This program is free software licensed under GNU GPL License v.2 ; see main.cpp fo details
 *   Эта программа является свободным программным обеспечением; распространяемым под
 *   лицензией GNU General Public License v.2 (УНИВЕРСАЛЬНАЯ ОБЩЕСТВЕННАЯ ЛИЦЕНЗИЯ GNU версия 2.0) 
 * ----------------------------------------------------------------------- */
/*
 * t_FileListElement.cpp
 *
 *  Created on: 18.11.2008
 *      Author: Denjs
 */

#include "t_FileListElement.h"
//============================================================
t_FileListElement::t_FileListElement(QObject *parent )
		: t_AbstractQDroidBot(parent)
{

}

//============================================================
// needs to have ability to be included to QList
t_FileListElement::t_FileListElement(const t_FileListElement &other)// needs to be included to QList
{
	//qDebug()<<"t_FileListElement::t_FileListElement(t_FileListElement&):[0020]: other.Note1_inc =" << other.Note1_inc;
	this->set_note1(other.Note1_inc);//other.get_note1()
	this->set_note2(other.Note2_inc);
	this->set_path(other.Path_inc);
	this->set_relpath(other.RelativePath_inc);
	this->set_file_full_name(other.FileFullName_inc);
	this->ID_inc=other.ID_inc;
	this->Parent_ID_inc=other.Parent_ID_inc;
	this->Properties=other.Properties;
	//qDebug()<<"t_FileListElement::t_FileListElement(t_FileListElement&):[0024]: this->Note1_inc =" << this->Note1_inc;

	//return *this;
}
/**/
//============================================================
// needs to be included to QList
t_FileListElement& t_FileListElement::operator=(const t_FileListElement &other)
{
	//qDebug()<<"t_FileListElement::operator=:[0033]: other.Note1_inc =" << other.Note1_inc;
	this->set_note1(other.Note1_inc);//other.get_note1()
	this->set_note2(other.Note2_inc);
	this->set_path(other.Path_inc);
	this->set_relpath(other.RelativePath_inc);
	this->set_file_full_name(other.FileFullName_inc);
	this->ID_inc=other.ID_inc;
	this->Parent_ID_inc=other.Parent_ID_inc;
	this->Properties=other.Properties;
	//qDebug()<<"t_FileListElement::operator=:[0037]: this->Note1_inc =" << this->Note1_inc;

	return *this;
}

//============================================================
// а это нужно для добавления в QSet (шаг 2.2)
bool t_FileListElement::operator==(const t_FileListElement &other ) const
{
	bool rez=true;
	rez=(this->ID_inc==other.ID_inc);
	return rez;
}


/**/

//============================================================
/* virtual function to be redefined to make real class */
QString t_FileListElement::std_in(QString Message)
{

}

//============================================================
QString t_FileListElement::get_file_full_name()
{
	return FileFullName_inc;
}

//============================================================
QString t_FileListElement::set_file_full_name(QString _FileFullName)
{
	QString OldFileFullName;
	OldFileFullName=FileFullName_inc;
	FileFullName_inc=_FileFullName;
	return OldFileFullName;
}

//============================================================
QString t_FileListElement::get_note1()
{
	return Note1_inc;
}

//============================================================
QString t_FileListElement::set_note1(QString _Note1)
{
	QString OldNote;
	OldNote=Note1_inc;
	Note1_inc=_Note1;
	return OldNote;
}

//============================================================
QString t_FileListElement::get_note2()
{
	return Note2_inc;
}

//============================================================
QString t_FileListElement::set_note2(QString _Note2)
{
	QString OldNote;
	OldNote=Note2_inc;
	Note2_inc=_Note2;
	return OldNote;
}

//============================================================
QString t_FileListElement::get_path()
{
	return Path_inc;
}

//============================================================
QString t_FileListElement::set_path(QString _Note2)
{
	QString OldPath;
	OldPath=Path_inc;
	Path_inc=_Note2;
	return OldPath;
}
//============================================================
QString t_FileListElement::get_relpath()
{
	return RelativePath_inc;
}

//============================================================
QString t_FileListElement::set_relpath(QString _Note2)
{
	QString OldPath;
	OldPath=RelativePath_inc;
	RelativePath_inc=_Note2;
	return OldPath;
}

//============================================================
QString t_FileListElement::get_id()
{
	return ID_inc;
}

//============================================================
//QW: не знаю что будет если изменить ID у занесенного в QSet элемента
// вероятно ничего, ибо хеш для множества не должен поменяться...?
//RE: нормально! - QSet не позволяет менять элементы пока они внутри контейнера.
QString t_FileListElement::set_id(QString _Note2)
{
	QString OldID;
	OldID=ID_inc;
	ID_inc=_Note2;
	return OldID;
}

//============================================================
t_FileListElement* t_FileListElement::copy()
{
	t_FileListElement *El;
	El=new t_FileListElement();
	*El=*this;
	return El;
}
//============================================================
//QTreeWidgetItem* t_FileListElement::create_tree_widget_item() //создаем элемент отображдения для дерева
t_TreeWidgetItem* t_FileListElement::create_tree_widget_item(QString PropertyOrder) //создаем элемент отображдения для дерева
{
// ввести в список свойств предопределенные элементы?
// типа ID, Name

//Обязательно должны быть
	 //ID (ID_inc)
	 //и пусть будет PATH /Path_inc

	 QStringList PropertyOrderList = QString(PropertyOrder).split(",");
	 PropertyOrderList.append("");//костыль, на тот случай что бы далее были определны все элементы к которым случимся по индексу.
	 PropertyOrderList.append("");
	 PropertyOrderList.append("");
	 PropertyOrderList.append("");
	 PropertyOrderList.append("");

	 t_TreeWidgetItem *TTreeWidgetItem;
	 TTreeWidgetItem=new t_TreeWidgetItem();
	 QTreeWidgetItem *OrigTreeWidgetItem;
	 OrigTreeWidgetItem=new QTreeWidgetItem();
	 OrigTreeWidgetItem->setText(0,FileFullName_inc);
	 OrigTreeWidgetItem->setText(1,Properties[PropertyOrderList[0]]);
	 OrigTreeWidgetItem->setText(2,Properties[PropertyOrderList[1]]);
	 OrigTreeWidgetItem->setText(3,Properties[PropertyOrderList[2]]);
	 OrigTreeWidgetItem->setText(4,Properties[PropertyOrderList[3]]);
	 OrigTreeWidgetItem->setText(5,Properties[PropertyOrderList[4]]);

	 //OrigTreeWidgetItem->setText(6,RelativePath_inc);
	 //OrigTreeWidgetItem->setText(7,Note1_inc);
	 //OrigTreeWidgetItem->setText(8,Note2_inc);
	 //OrigTreeWidgetItem->setText(9,Parent_ID_inc); //!
	 OrigTreeWidgetItem->setText(10,ID_inc); //!
	 OrigTreeWidgetItem->setText(11,RelativePath_inc);


	 OrigTreeWidgetItem->setFlags(OrigTreeWidgetItem->flags()|Qt::ItemIsEditable);//|Qt::ItemIsUserCheckable
	 //OrigTreeWidgetItem->setDisabled(true);

	 TTreeWidgetItem->set_qwidgetitem(OrigTreeWidgetItem);
	 return TTreeWidgetItem;
}
/**/



/*
 ===================================================================
    работа со списком свойств
 ===================================================================
*/
QString t_FileListElement::get_property(QString _ValueName)
{
	return this->Properties.value(_ValueName);
}
QString t_FileListElement::set_property(QString _ValueName,QString _ValueVar)
{
	this->Properties[_ValueName]=_ValueVar;
	return "";
}

bool t_FileListElement::is_property_contains(QString _ValueName)
{
	return Properties.contains(_ValueName);
}

int t_FileListElement::remove_property(QString _ValueName)
{
	return Properties.remove(_ValueName);
}

int t_FileListElement::remove_all_properties()
{
	Properties.clear();
	return 0;
}

int t_FileListElement::property_count()
{
	return Properties.size();
}

//по индексу - получить свойство (индекс с нуля начинается!)
QString t_FileListElement::get_property_name(int _index)
{
	QMap<QString,QString>::const_iterator i_prop;
	if ((_index+1)>Properties.size()) return QString();//нет такого - индекс большой
	i_prop = this->Properties.begin();
	i_prop+=_index;//slow? yes... <_<
	return i_prop.key();//TODO! get_property_name
}

//по индексу - получить значение (индекс с нуля начинается!)
QString t_FileListElement::get_property_value(int _index)
{
	QMap<QString,QString>::const_iterator i_prop;
	if ((_index+1)>Properties.size()) return QString();//нет такого - индекс большой
	i_prop = this->Properties.begin();
	i_prop+=_index;//slow? yes... <_<
	return i_prop.value();//TODO! get_property_name
}

// переименовать свойство
int t_FileListElement::rename_property(QString _ValueNameOld, QString _ValueNameNew, bool Replace)
{
	QString Value;
	if (Properties.contains(_ValueNameNew))
	 {
		if (Replace)
			{
				Properties[_ValueNameNew]=Properties[_ValueNameOld];
				Properties.remove(_ValueNameOld);
				return 2;
			}
		  else
			{
				Properties.remove(_ValueNameOld);
				return 1;
			};
	 };//if (Properties.contains(_ValueNameNew))
	Properties[_ValueNameNew]=Properties[_ValueNameOld];
	Properties.remove(_ValueNameOld);
	return 0;
}
